﻿using msBsc.AppLogic.DataAlc;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi
{
    public partial class wfRouteList : msBsc.Cls.BPageHt
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        //获取路线列表
        public void GetRouteList() {

            int pRows =0;

            int.TryParse(this.GetParamHtValue("pRows"), out pRows);

            int pIndex = 0;
            int.TryParse(this.GetParamHtValue("pIndex"),out pIndex);

            string rTitle = this.GetParamHtValue("rTitle");

            string county = this.GetParamHtValue("county");
            county = county == "0" ? "" : county;
            string city = this.GetParamHtValue("city");
            city = city == "0" ? "" : city;
            string destination = this.GetParamHtValue("destination");
            destination = destination == "0" ? "" : destination;

            using (CBizRoute route=new CBizRoute ())
            {
                DataTable dtRoute = route.GetRouteList(rTitle, county, city, destination, pRows, pIndex);
                if (dtRoute==null)
                {
                    this.ExecJScript(@"$('#routeList').html('<tr><td> <p>没有任何的数据...</p></td></tr>')");
                    return;
                }
                string retJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(dtRoute, "", "", 1, 20, "");

                this.ExecJScript(@"
                            var _html = $('#svc_list_temp_vehicle').html();

                            laytpl(_html).render(" + retJson + @", function (render) {
                                $('#routeList').html(render);
                                            });jsPage('divPage', " + Convert.ToInt32(dtRoute.Rows[0]["ROWSCOUNT"].ToString()) + ", " + pRows + ", " + pIndex + ", 'goPage');");

            }

            
        }
        //地区加载
        private void RefreshArea()
        {
            string countryId = this.GetParamHtValue("countryId");
            string cityId = this.GetParamHtValue("cityId");

            DataSet ds1, ds2;

            using (msBsc.AppLogic.DataAlc.CBizCountryCity objCBizCountryCity = new AppLogic.DataAlc.CBizCountryCity())
            {
                ds1 = string.IsNullOrEmpty(countryId) ? null : objCBizCountryCity.SelectCountryByParentId(countryId);

                ds2 = string.IsNullOrEmpty(cityId) ? null : objCBizCountryCity.SelectCountryByParentId(cityId);
            }

            if (ds1 != null)
            {
                var countryJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds1.Tables[0], "", "", 1, 200, "");
                this.ExecJScript(@"var _html = $('#country_city_list').html();
                            laytpl(_html).render(" + countryJson + @", function (render) {
                                $('#selCity').html(render);
                            });");
            }

            if (ds2 != null)
            {
                var cityJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds2.Tables[0], "", "", 1, 200, "");
                this.ExecJScript(@"var _html = $('#city_des_list').html();
                            laytpl(_html).render(" + cityJson + @", function (render) {
                                $('#selDestination').html(render);
                            });");
            }
        }
        public override void DoAction()
        {
            if (this.strAction == "init")
            {
                GetRouteList();
            }
            else if (this.strAction == "changeArea")
            {
                RefreshArea();
            }
        }
    }
}